package com.example.neteasemusic.viewPager2

import android.media.MediaPlayer
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.viewpager2.widget.ViewPager2
import com.example.neteasemusic.MainActivity
import com.example.neteasemusic.databinding.FragmentMainBinding
import com.example.neteasemusic.recyclerView.FindFragment


class MainFragment : Fragment() {
    private lateinit var binding:FragmentMainBinding


    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        binding = FragmentMainBinding.inflate(inflater,container,false)
        return binding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)


        val fragments =
            arrayListOf(FindFragment(), MineFragment(), CommunityFragment(), InterestFragment())
        val myAdapter = MyAdapter(fragments, requireActivity().supportFragmentManager, lifecycle)
        binding.viewPager2.apply {
            this.orientation  = ViewPager2.ORIENTATION_HORIZONTAL
            adapter = myAdapter
            //禁止用户滑动
            this.isUserInputEnabled = false
        }

        binding.bottomTabBar.callback = {
            binding.viewPager2.setCurrentItem(it,false)
        }

        binding.list.setOnClickListener {
            val activity = requireActivity() as MainActivity
            //打开菜单
            activity.layout.open()
        }


    }

}